/**
 * created by dqn 2018/3/7 19:22
 */

package main.repository;

import main.entity.Song;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;
@Repository
@Transactional
public interface SongRepository extends CrudRepository<Song, Integer>, JpaSpecificationExecutor<Song> {
    /**
     * 搜素功能
     *
     * @param key  关键字
     * @return
     */
    public Optional<List<Song>> getSongsByNameContains(String key);
    public Optional<List<Song>> getSongsByLyricContains(String key);
    public Optional<List<Song>> getSongsBySingerContains(String key);

    public Song getSongByPk(int pk);

    public Page<Song> getSongsByStyle(String style, Pageable pageable);

    public Page<Song> getSongsByLanguage(String language, Pageable pageable);

    /**
     * 歌名精确查询。
     *
     * @param name 歌名
     * @return Optional song.a
     */
    public Optional<Song> getSongsByName(String name);

    public Page<Song> findAll(Pageable pageable);

    public Page<Song> findAllByPkAfter(int pk, Pageable pageable);
}
